#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string multiply(string num1, string num2) {
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());

        int m = num1.size(), n = num2.size();
        vector<int> v(m + n - 1);

        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++) {
                v[i + j] += (num1[i] - '0') * (num2[j] - '0');

            }
        string str;
        int cur = 0, t = 0;
        while (cur < m + n - 1 || t != 0) {
            if (cur < m + n - 1)
                t += v[cur++];
            str += t % 10 + '0';
            cout << str[cur - 1] << ' ';
            t /= 10;
        }

        while (str.size() > 1 && str.back() == '0')
            str.pop_back();
        reverse(str.begin(), str.end());
        return str;
    }
};